package com.ruoyi.animal.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.animal.domain.AnimalSpecies;
import com.ruoyi.animal.service.IAnimalSpeciesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 动物类型Controller
 * 
 * @author gw
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/species")
public class AnimalSpeciesController extends BaseController
{
    @Autowired
    private IAnimalSpeciesService animalSpeciesService;

    /**
     * 查询动物类型列表
     */
    @RequiresPermissions("animal:species:list")
    @GetMapping("/list")
    public AjaxResult list(AnimalSpecies animalSpecies)
    {
        List<AnimalSpecies> list = animalSpeciesService.selectAnimalSpeciesList(animalSpecies);
        return success(list);
    }

    /**
     * 导出动物类型列表
     */
    @RequiresPermissions("animal:species:export")
    @Log(title = "动物类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnimalSpecies animalSpecies)
    {
        List<AnimalSpecies> list = animalSpeciesService.selectAnimalSpeciesList(animalSpecies);
        ExcelUtil<AnimalSpecies> util = new ExcelUtil<AnimalSpecies>(AnimalSpecies.class);
        util.exportExcel(response, list, "动物类型数据");
    }

    /**
     * 获取动物类型详细信息
     */
    @RequiresPermissions("animal:species:query")
    @GetMapping(value = "/{speciesId}")
    public AjaxResult getInfo(@PathVariable("speciesId") Long speciesId)
    {
        return success(animalSpeciesService.selectAnimalSpeciesBySpeciesId(speciesId));
    }

    /**
     * 新增动物类型
     */
    @RequiresPermissions("animal:species:add")
    @Log(title = "动物类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AnimalSpecies animalSpecies)
    {
        return toAjax(animalSpeciesService.insertAnimalSpecies(animalSpecies));
    }

    /**
     * 修改动物类型
     */
    @RequiresPermissions("animal:species:edit")
    @Log(title = "动物类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AnimalSpecies animalSpecies)
    {
        return toAjax(animalSpeciesService.updateAnimalSpecies(animalSpecies));
    }

    /**
     * 删除动物类型
     */
    @RequiresPermissions("animal:species:remove")
    @Log(title = "动物类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{speciesIds}")
    public AjaxResult remove(@PathVariable Long[] speciesIds)
    {
        return toAjax(animalSpeciesService.deleteAnimalSpeciesBySpeciesIds(speciesIds));
    }
}
